/******************************************************
 *                                                     
 *              Score System               
 *                                                     
 *******************************************************/

/**
 * TeacherTbl.java
 *
 * @author sundy
 * @version 0.0.1
 * lastModified 2011-01-01
 */

package com.sundy.service;

import java.util.List;

import com.sundy.core.Common;
import com.sundy.daosupport.RightTblDAO;
import com.sundy.daosupport.SubjectTblDAO;

/**
 * TeacherTbl entity. @author MyEclipse Persistence Tools
 */

public class TeacherTbl implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 6651363870562736992L;
	private Integer id;
	private String name;
	private String password;
	private Integer admin;

	// Constructors

	/** default constructor */
	public TeacherTbl() {
	}

	/** full constructor */
	public TeacherTbl(String name, String password, Integer admin) {
		this.name = name;
		this.password = password;
		this.admin = admin;
	}

	// Property accessors

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getAdmin() {
		return admin;
	}

	public void setAdmin(Integer admin) {
		this.admin = admin;
	}

	public int getSubjectType() {
		RightTblDAO dao = RightTblDAO
				.getFromApplicationContext(Common.applicationContext);
		List<RightTbl> list = dao.findByTeacherId(this.id);
		if (list == null || list.isEmpty()) {
			return -1;
		} else {
			int id = list.get(0).getSubjectId();
			SubjectTblDAO dao2 = SubjectTblDAO
					.getFromApplicationContext(Common.applicationContext);
			SubjectTbl subject = dao2.findById(id);
			String subjectTypeText = subject.getCaption();
			if (subjectTypeText.endsWith("-文")) {
				return 1;
			} else
				return 0;
		}
	}

	public int getSubject() {
		RightTblDAO dao = RightTblDAO
				.getFromApplicationContext(Common.applicationContext);
		List<RightTbl> list = dao.findByTeacherId(this.id);
		if (list == null || list.isEmpty()) {
			return -1;
		} else {
			return list.get(0).getSubjectId();
		}
	}
}